package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by XXX on 2017/5/23.
 */

public class ImgGradeAdapter extends BaseAdapter{

    private Context context;
    private List<String> list;

    public ImgGradeAdapter( Context context,List<String> list){
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.image_display_view,parent,false);
            holder=new ViewHolder();
            holder.ItemImage = convertView.findViewById(R.id.ItemImage);
            holder.playIcon = convertView.findViewById(R.id.playIcon);
            convertView.setTag(holder);
        }else{
           holder= (ViewHolder) convertView.getTag();
        }
        Log.e("fileStr",list.get(position));
        if (list.get(position).endsWith(".mp4")){
            holder.playIcon.setVisibility(View.VISIBLE);
        }else{
            holder.playIcon.setVisibility(View.GONE);
        }
        Glide.with(context).load(list.get(position)).thumbnail(0.1f).into(holder.ItemImage);
        return  convertView;
    }

    class ViewHolder{
        ImageView ItemImage;
        ImageView playIcon;
    }

}
